Namespaces

The namespace attribute allows you to segregate action configurations into namespaces, so that you may use the same action alias in more than one namespace with different classes, parameters, etc. This is in contrast to Webwork 1.x, where all action names and aliases were global and could not be re-used in an application.

Default Namespace

The default namespace, which is "" (an empty string) is used as a "catch-all" namespace, so if an action configuration is not found in a specified namespace, the default namespace will also be searched. This allows you to have global action configurations outside of the "extends" hierarchy, as well as to allow the previous Webwork 1.x behavior by not specifying namespaces. It is also intended that the namespace functionality can be used for security, for instance by having the path before the action name be used as the namespace by the Webwork 2.0 ServletDispatcher, thus allowing the use of J2EE declarative security on paths to be easily implemented and maintained.

Root Namesapce

Root namespace, which is "/" is also allowed in WebWork. It will be the namespace when a request directly under the context path is received. As with other namespace, it will fall back to the default namespace if no such action alias is found in it.

Namespace example

<package name="default">
    <action name="foo" class="mypackage.simpleAction>
        <result name="success" type="dispatcher">greeting.jsp</result>
    </action>
    <action name="bar" class="mypackage.simpleAction"> 
        <result name="success" type="dispatcher">bar1.jsp</result> 
    </action> 
</package>

<package name="mypackage1" namespace="/">
    <action name="moo" class="mypackage.simpleActtion">
        <result name="success" type="dispatcher">moo.jsp</result>
    </action>
</package>

<package name="mypackage2" namespace="/barspace"> 
    <action name="bar" class="mypackage.simpleAction"> 
        <result name="success" type="dispatcher">bar2.jsp</result> 
    </action> 
</package>

Explanation

If a request for /barspace/bar.action is made, '/barspace' namespace is searched and if it is found the bar action is executed, else it will fall back to the default namespace. In this example bar alias do exists in the '/barspace' namespace, so it will get executed and if success, the request will be forwarded to bar2.jsp.

Note: If a request is made to /barspace/foo.action, the action foo will be searched for in a namespace of /barspace. If the action is not found, the action will then be searched for in the default namespace. Unless specified, the default namespace will be "". In our example above, their is no action foo in the namespace /barspace, therefore the default will be searched and /foo.action will be executed.

If a request for /moo.action is made, the root namespace ('/') is searched for 'moo' action alias, if it is not found it will fall back to trying to find it in the default namespace. In this example, moo action alias does exists and hence will be executed. Upon sucess, the request will get forwarded to bar2.jsp.

Note: If a request is made to '/foo.action', '/' namespace will be searched and if it is found it will be execueted, else an attempt to try to find it in the default namespace will occurred. In this example foo action alias does not exist in the '/' namespace, hence it will falled back to the default namespace and execute the foo alias there.

Note: Namespace is only one level. For example if the url '/barspace/myspace/bar.action' is requested, Webwork will try to search for namespace '/barspace/myspace', which does not exist in this case, and will fall back to the default namespace '' and tried the search for action with 'bar' alias. As a result the bar action in the default will be used.